//
//  ZFAccountModal.swift
//  map
//
//  Created by fyzq on 2024/2/4.
//

import UIKit
import RealmSwift
class ZFAccountModal: Object {

    @Persisted(primaryKey: true) var uuid: String
//    @Persisted var telephone:String = ""
//    @Persisted var password:String?
    @Persisted var userName:String?
    @Persisted var picture:String?
    @Persisted var sex:Int = 1
    @Persisted var remark:String = ""
    
}

extension ZFAccountModal {
    
    static func setupDefalut(){
        
        ///1获取当前设备uuid
        let uuid = String.UUID()
        ///根据UUId 来配用户置数据库
        let predicate = NSPredicate(format: "uuid == %@", uuid)
        guard let accounts = ZFRealmManager.objectsWithPredicate(object: ZFAccountModal.self, predicate: predicate),accounts.count > 0 else {
            ///查询不到用户 创建用户
            return onCreateAccount()
        }
    }
    
    ///没有用户 创建用户
    fileprivate static func onCreateAccount(){
        let account = ZFAccountModal()
        account.uuid = String.UUID()
        ZFRealmManager.add(account){
            print("创建默认用户成功")
        }
    }
    


    
    
}

